#include "qmyNaracki.h"


QMyNaracki::QMyNaracki(QWidget *parent)
    : QMyBaseWidget(parent)
    ,NarackiVnes(0)
    ,NarackiKorekcija(0)
    ,NarackiLista(0)
    ,NarackiWizard(0)
	,m_row(0)
{
    ui.setupUi(this);
    pressF4();
}

QMyNaracki::~QMyNaracki()
{

}
void QMyNaracki::pressF2()
{
    closeAllForm();
    NarackiVnes = showMyWidget<QNarackiVnes>(NarackiVnes); 
    NarackiVnes->setCategoryWidget(this);
    connect(NarackiVnes,SIGNAL(closeW()),this,SLOT(closeW()));
    connect(NarackiVnes,SIGNAL(scallKomintenti(QWidget*, QString)),this,SLOT(callKomintenti(QWidget*, QString)));
    connect(NarackiVnes,SIGNAL(scallArtikli(QWidget*, QString)),this,SLOT(callArtikli(QWidget*, QString)));
	emit disablePrint(true);
}
void QMyNaracki::pressF3()
{
    if(!NarackiLista)
    {
        return;
    }
	if(!NarackiLista->isDisabledButtonF3())
	{
		return;
	}

    int id = NarackiLista->getSelectedId();
    closeAllForm();
    NarackiKorekcija = showMyWidget<QNarackiKorekcija>(NarackiKorekcija); 
    NarackiKorekcija->setCategoryWidget(this);
    connect(NarackiKorekcija,SIGNAL(closeW()),this,SLOT(closeW()));
    connect(NarackiKorekcija,SIGNAL(scallKomintenti(QWidget*, QString)),this,SLOT(callKomintenti(QWidget*, QString)));
    connect(NarackiKorekcija,SIGNAL(scallArtikli(QWidget*, QString)),this,SLOT(callArtikli(QWidget*, QString)));
    NarackiKorekcija->init(id);
	emit disablePrint(true);
}
void QMyNaracki::pressF4()
{
    closeAllForm();
    NarackiLista = showMyWidget<QNarackiLista>(NarackiLista); 
    NarackiLista->setCategoryWidget(this);
	NarackiLista->setRow(m_row);
    connect(NarackiLista, SIGNAL(closeW()), this, SLOT(closeWLista()));
    connect(NarackiLista, SIGNAL(procF2()), this, SLOT(procF2()));
    connect(NarackiLista, SIGNAL(procF3()), this, SLOT(procF3()));
    connect(NarackiLista, SIGNAL(procF6()), this, SLOT(procF6()));
    connect(NarackiLista, SIGNAL(procDel()), this, SLOT(procDel()));
	emit disablePrint(false);
}

void QMyNaracki::pressF6()
{
    if(!NarackiLista)
    {
        return;
    }
    if (NarackiLista->getStatusEnableF6())
    {
        int id = NarackiLista->getSelectedId();
        closeAllForm();
        NarackiWizard = showMyWidget<QNarackiWizard>(NarackiWizard); 
        NarackiWizard->setCategoryWidget(this);
        connect(NarackiWizard, SIGNAL(closeW()),this,SLOT(closeW()));
        connect(NarackiWizard, SIGNAL(scallKomintenti(QWidget*, QString)),this,SLOT(callKomintenti(QWidget*, QString)));
        connect(NarackiWizard, SIGNAL(scallArtikli(QWidget*, QString)),this,SLOT(callArtikli(QWidget*, QString)));
        connect(NarackiWizard, SIGNAL(scallProizvodi(QWidget*, QString)),this,SLOT(callProizvodi(QWidget*, QString)));

        NarackiWizard->init(id);
        emit disablePrint(true);
    }
}

void QMyNaracki::callProizvodi(QWidget* myobj, QString text)
{
    emit signProizvodiFromNalog(myobj, text);
}

void QMyNaracki::procF2()
{
    pressF2();
}
void QMyNaracki::procF3()
{
    pressF3();
}

void QMyNaracki::procF6()
{
    pressF6();
}

void QMyNaracki::refresh()
{
}

void QMyNaracki::procDel()
{

}
void QMyNaracki::pressEscape()
{
    this->raise();
    this->setFocus();
	emit disablePrint(true);
    emit signCloseMyWidget();
}
void QMyNaracki::closeW()
{
    pressF4();
}
void QMyNaracki::closeWLista()
{
    pressEscape();
}

void QMyNaracki::closeAllForm()
{
    NarackiKorekcija = deleteMyWidget<QNarackiKorekcija>(NarackiKorekcija);
    NarackiVnes = deleteMyWidget<QNarackiVnes>(NarackiVnes);
	if (NarackiLista)
	{
		m_row = NarackiLista->getRow();
	}
    NarackiLista = deleteMyWidget<QNarackiLista>(NarackiLista);
    NarackiWizard = deleteMyWidget<QNarackiWizard>(NarackiWizard);
}
void QMyNaracki::callKomintenti(QWidget* myobj, QString text)
{
    emit signKomintentiFromIspratnica(myobj, text);
}

void QMyNaracki::callArtikli(QWidget* myobj, QString text)
{
    emit signArtikliFromIspratnica(myobj, text);
}

void QMyNaracki::sendPrintMessage()
{
    emit signPrint();
}


QStandardItemModel* QMyNaracki::getModel()
{
    QStandardItemModel * modelExt;
    if (NarackiLista)
    {
        modelExt = NarackiLista->model;
    } 
    else
    {
        modelExt = NULL;
    }
    return modelExt;
}

QStandardItemModel* QMyNaracki::getModel2()
{
    QStandardItemModel * modelExt;
    if (NarackiLista)
    {
        modelExt = NarackiLista->model2;
    } 
    else
    {
        modelExt = NULL;
    }
    return modelExt;
}

QStringList QMyNaracki::getIspratnicaInfo()
{
	QStringList modelExt;
	modelExt.clear();

	if (NarackiLista)
	{
		modelExt = NarackiLista->geInfo();
	} 
	else
	{
		modelExt;
	}
	return modelExt;
}